<UserControl x:Class="wpf.QueueControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:wpf">
  <UserControl.Resources>
    <local:QueueItemsComparator x:Key="QueueItemsComparator"/>
    <local:TrackMetadataConverter x:Key="TrackMetadataConverter"/>
    <local:AlbumArtUriConverter x:Key="AlbumArtUriConverter"/>
  </UserControl.Resources>
  <DockPanel>
    <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" MinHeight="136">
      <Image Height="128" Width="128" Margin="4" Stretch="Uniform" VerticalAlignment="Top">
        <Image.Source>
          <MultiBinding Converter="{StaticResource AlbumArtUriConverter}" Mode="OneWay">
            <Binding Path="Coordinator.AVTransport.CurrentTrackMetaData"/>
            <Binding Path="Coordinator.DocumentUrl"/>
          </MultiBinding>
        </Image.Source>
      </Image>
      <TextBlock Margin="4">
        <TextBlock Text="Track"/>
        <LineBreak/>
        <TextBlock TextBlock.FontWeight="Bold" Text="{Binding Path=Coordinator.AVTransport.CurrentTrackMetaData, Converter={StaticResource TrackMetadataConverter}, ConverterParameter='Title'}"/>
        <LineBreak/>
        <TextBlock Text="Artist"/>
        <LineBreak/>
        <TextBlock TextBlock.FontWeight="Bold" Text="{Binding Path=Coordinator.AVTransport.CurrentTrackMetaData, Converter={StaticResource TrackMetadataConverter}, ConverterParameter='Creator'}"/>
        <LineBreak/>
        <TextBlock Text="Album"/>
        <LineBreak/>
        <TextBlock TextBlock.FontWeight="Bold" Text="{Binding Path=Coordinator.AVTransport.CurrentTrackMetaData, Converter={StaticResource TrackMetadataConverter}, ConverterParameter='Album'}"/>
      </TextBlock>
      <TextBlock>
        <Expander ExpandDirection="Right">
          <TextBlock>
            <TextBlock Text="SystemUpdateID: "/>
            <TextBlock Text="{Binding Path=Coordinator.ContentDirectory.SystemUpdateID}"/>
            <LineBreak/>
            <TextBlock Text="ContainerUpdateIDs: "/>
            <TextBlock Text="{Binding Path=Coordinator.ContentDirectory.ContainerUpdateIDs}"/>
            <LineBreak/>
            <TextBlock Text="ShareListRefreshState: "/>
            <TextBlock Text="{Binding Path=Coordinator.ContentDirectory.ShareListRefreshState}"/>
            <LineBreak/>
            <TextBlock Text="ShareIndexInProgress: "/>
            <TextBlock Text="{Binding Path=Coordinator.ContentDirectory.ShareIndexInProgress}"/>
            <LineBreak/>
            <TextBlock Text="ShareIndexLastError: "/>
            <TextBlock Text="{Binding Path=Coordinator.ContentDirectory.ShareIndexLastError}"/>
            <LineBreak/>
            <TextBlock Text="UserRadioUpdateID: "/>
            <TextBlock Text="{Binding Path=Coordinator.ContentDirectory.UserRadioUpdateID}"/>
            <LineBreak/>
            <TextBlock Text="MasterRadioUpdateID: "/>
            <TextBlock Text="{Binding Path=Coordinator.ContentDirectory.MasterRadioUpdateID}"/>
            <LineBreak/>
            <TextBlock Text="SavedQueuesUpdateID: "/>
            <TextBlock Text="{Binding Path=Coordinator.ContentDirectory.SavedQueuesUpdateID}"/>
            <LineBreak/>
            <TextBlock Text="ShareListUpdateID: "/>
            <TextBlock Text="{Binding Path=Coordinator.ContentDirectory.ShareListUpdateID}"/>
          </TextBlock>
        </Expander>
      </TextBlock>
    </StackPanel>
    <ScrollViewer DockPanel.Dock="Bottom">
      <ListView
        ItemsSource="{Binding Path=Coordinator.Queue}"
        VirtualizingStackPanel.IsVirtualizing="True"
        KeyDown="WindowKeyDown"
        MouseDoubleClick="ListDoubleClick">
        <ListView.View>
          <GridView AllowsColumnReorder="True">
            <GridViewColumn DisplayMemberBinding="{Binding Path=Artist}" Header="Artist" />
            <GridViewColumn DisplayMemberBinding="{Binding Path=Album}" Header="Album" />
            <GridViewColumn DisplayMemberBinding="{Binding Path=Title}" Header="Title" />
          </GridView>
        </ListView.View>
        <ListView.ItemContainerStyle>
          <Style TargetType="{x:Type ListViewItem}">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Style.Triggers>
              <DataTrigger Value="True">
                <DataTrigger.Binding>
                  <MultiBinding Converter="{StaticResource QueueItemsComparator}" Mode="OneWay" FallbackValue="False">
                    <Binding Path="DataContext.Coordinator.AVTransport.CurrentTrack" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type ScrollViewer}}"/>
                    <Binding Path="NumericID"/>
                    <Binding Path="DataContext.Coordinator.AVTransport.CurrentTrackUri" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type ScrollViewer}}"/>
                    <Binding Path="Res"/>
                  </MultiBinding>
                </DataTrigger.Binding>
                <Setter Property="FontWeight" Value="Bold"/>
              </DataTrigger>
            </Style.Triggers>
          </Style>
        </ListView.ItemContainerStyle>
      </ListView>
    </ScrollViewer>
  </DockPanel>
</UserControl>
